<?php
    header("Content-type:text/html;charset=utf-8");
    $rows = file_get_contents('php://input');
    if($rows){
        /** 创建数组 **/
        $arr = array();
        $arr['data'] = array();
        /** 创建数组 **/
        $d = json_decode($rows);
        include '../../api/config.php';
        include './comm.php';
        if(($d->head) === 30001){
           
            if(flag($d)){
                $sql_1 = "SELECT * FROM sys_email";
                $stmt = $conn->query($sql_1);
                $stmt->execute();
                $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
                $result = $stmt->fetchAll();
                $result[0]['email_pos'] = "******";
                echo get_msg('200','操作成功~',false,$result);
            }else{
                echo get_msg('500','权限不足~','../index.html',false);
            };
        };

        if(($d->head) === 30000){
            if(flag($d)){
                $sql_1 = "SELECT * FROM sys_email";
                $stmt = $conn->query($sql_1);
                $stmt->execute();
                $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
                $result = $stmt->fetchAll();
                
                if($result){
                    $sql_3 = "UPDATE sys_email SET SMTP_name='$d->SMTP_name',SMTP_port='$d->SMTP_port',email_pos='$d->email_pos',email_name='$d->email_name',email='$d->email'";
                    $stmt = $conn->prepare($sql_3);
                    $stmt->execute();
                    echo get_msg('200','操作成功~',false,false);
                }else{
                    $sql_2 = "INSERT INTO sys_email(SMTP_name,SMTP_port,email_pos,email_name,email) VALUES('$d->SMTP_name','$d->SMTP_port','$d->email_pos','$d->email_name','$d->email')";
                    $stmt = $conn->prepare($sql_2);
                    $stmt->execute();
                    echo get_msg('200','操作成功~',false,false);
                };//如果存在则修改，不存在则添加

            }else{
                echo get_msg('500','权限不足~','../index.html',false);
            };
        };
    }else{
        $conn = null;
        echo "<script>\r\n    window.location.href = '../../';\r\n    </script>";
    };
    $conn = null;
?>